import Vue from 'vue'
// import Home from "../views/Home.vue"
const Home=()=>import("../views/Home.vue")
import Router from 'vue-router'
// import Reg from "../views/Reg.vue"
import Reg1 from "../views/Reg1.vue"
import Reg2 from "../views/Reg2.vue"
// import Login from "../views/Login.vue"
// import GoodsDetail from "../views/GoodsDetail.vue"
// import My from "../views/My.vue"
const My =()=>import(/* webpackChunkName:'demot' */ "../views/My.vue")
const GoodsDetail =()=>import(/* webpackChunkName:'demot' */ "../views/GoodsDetail.vue")
import ShoppingCar from "../views/ShoppingCar.vue"
import Category from "../views/Category.vue"
import Search from "../views/Search.vue"

// import Brand from "../views/Brand.vue"


Vue.use(Router)

let router = new Router({
    routes: [
        {
            path: "/",
            component: Home
        },
        {
            path: "/Reg",
            // component: Reg,
            component:resolve=>require(["../views/Reg.vue"],resolve)
        },
        {
            path: "/Reg1",
            component: Reg1
        },
        {
            path: "/Reg2",
            component: Reg2
        },
        {
            path: "/GoodsDetail/:goodsid",
            component: GoodsDetail
        },
        {
            name: "My",
            path: "/My",
            component: My
        },
        {
            path: "/Search",
            component: Search
        },
        {
            path: "/Category",
            component: Category
        },
        {
            path: "/Login",
            // component: Login
            component:()=>import("../views/Login.vue")
        },
        {
            path: "/About",
            component:()=>import("../views/About.vue")
        },
        {
            path: "/Address",
            component: () => import("../views/Address.vue"),
            meta:{
                requiresAuth:true
            }
        },
        {
            path: "/Favorites",
            component:()=>import("../views/Favorites.vue")
        },
        {
            path: "/Set",
            component: () => import("../views/Set.vue"),
            meta:{
                requiresAuth:true
            }
        },
        {
            path: "/Pay",
            component:()=>import("../views/Pay.vue")
        },
        {
            path: "/AddressEdit",
            component:()=>import("../views/AddressEdit.vue")
        },
        {
            path: "/userOrder",
            component: () => import("../views/userOrder.vue"),
            meta:{
                requiresAuth:true
            }
        },
        {
            path: "/Brand",
            component:()=>import("../views/Brand.vue")
        },
        {
            path: "/SearchResult",
            component:()=>import("../views/SearchResult.vue")
        },
        {
            path: "/ShoppingCar",
            component: ShoppingCar,
            meta:{
                requiresAuth:true
            }
        },
        // {
        //     path:"/Brand/:",
        //     component:Brand
        // },

    ]
},
)
// 全局前置钩子。
router.beforeEach((to,from,next)=>{
    
    // if(to.path==="/ShoppingCar" || to.path=="/My" || to.path==""){
    if(to.meta.requiresAuth){
        // if(没有登录){
        if(!sessionStorage.getItem("token")){
            next("/Login?path="+to.path);
        }
    }
    next();
});
export default router